<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html lang="en">
	<head>
		<base href="<%=basePath%>">
		<meta charset="utf-8" />
		<%@ include file="../../share/layoutForm.jsp"%> 
	</head>
<body>
<form id="form1">
<div style="margin-left: 10px; margin-top: 20px; margin-right: 30px;">
    <table class="form">
        <tr>
            <th class="formTitle">上级部门<font face="宋体">*</font></th>
            <td class="formValue">
                <div id="OrganizeTree" type="selectTree" class="ui-select" isvalid="yes" checkexpession="NotNull"></div>
            </td>
            <th class="formTitle">负责人</th>
            <td class="formValue">
				<input id="managerId" type="text" class="form-control" />
            </td>
        </tr>
        <tr>
            <th class="formTitle">部门名称<font face="宋体">*</font></th>
            <td class="formValue">
                <input id="departmentName" type="text" onblur="$.ExistField(this.id,'<%=basePath%>sysDepartment/isExist.do')" class="form-control" placeholder="请输入名称" isvalid="yes" checkexpession="NotNull" />
            </td>
            <th class="formTitle">部门简称</th>
            <td class="formValue">
                <input id="shortName" type="text" class="form-control" />
            </td>
        </tr>
        <tr>
            <th class="formTitle">联系电话</th>
            <td class="formValue">
                <input id="departmentTelphone" type="text" class="form-control" />
            </td>
            <th class="formTitle">排序码</th>
            <td class="formValue">
                <input id="sortCode" type="text" class="form-control" value="5" />
            </td>
        </tr>
        <tr>
            <th class="formTitle">电子邮箱</th>
            <td class="formValue">
                <input id="departmentEmail" type="text" class="form-control" />
            </td>
            <th class="formTitle">联系传真</th>
            <td class="formValue">
                <input id="departmentFax" type="text" class="form-control" />
            </td>
        </tr>
        <tr>
            <th class="formTitle" valign="top" style="padding-top: 4px;">备注
            </th>
            <td class="formValue" colspan="3">
                <textarea id="otherMark" class="form-control" style="height: 70px;"></textarea>
            </td>
        </tr>
    </table>
</div>
</form>
<script>
    var keyValue = request('keyValue');
    var organizeId = request('departmentId');
    var departmentId = request('departmentId');
    var parentId = request('parentId');
    $(function () {
        initControl();
    })
    //初始化控件
    function initControl() {
        //上级部门
        $("#OrganizeTree").ComboBoxTree({
            url: "<%=basePath%>sysDepartment/treeJson.do",
            description: "==请选择==",
            height: "250px",
            click: function (item) {
                if (item.Sort == 'Organize') {
                    organizeId = item.id;
                    parentId = 0;
                } else {
                    parentId = item.id;
                }
            }
        });

        //获取表单
        if (!!keyValue) {
            $.SetForm({
                url: "<%=basePath%>sysDepartment/get.do",
                param: { keyValue: keyValue },
                success: function (data) {
					if(data.type=="0"){
						$("#form1").SetWebControls(data.rows);
						if (data.rows.parentId == 0) {
							$("#OrganizeTree").ComboBoxTreeSetValue(data.rows.organizeId);
						} else {
							$("#OrganizeTree").ComboBoxTreeSetValue(data.rows.parentId);
						}
						parentId = data.rows.parentId;
						organizeId = data.rows.organizeId;
					}else{
						dialogAlert(data.message, -1);
					}
                }
            });
        } else {
            $("#OrganizeTree").ComboBoxTreeSetValue(departmentId);
        }
    }
	
    //保存表单
    function AcceptClick() {
        if (!$('#form1').Validform()) {
            return false;
        }
        var postData = $("#form1").GetWebControls(keyValue);
        postData["organizeId"] = organizeId;
        postData["parentId"] = parentId;
        postData["manager"] = $("#managerId").attr('data-text');
        $.SaveForm({
            url: "<%=basePath%>sysDepartment/edit.do?keyValue=" + keyValue,
            param: postData,
            loading: "正在保存数据...",
            success: function () {
                $.currentIframe().$("#gridTable").resetSelection();
                $.currentIframe().$("#gridTable").trigger("reloadGrid");
            }
        })
    }
</script>
</body>
</html>